//
// Created by root on 2020/5/4.
//

#include "CommonFunction.h"

#include <sys/time.h>

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>

namespace commonfunction {
    std::string CreateUUID() {
        using boost::uuids::random_generator;
        static random_generator uuid_v4;
        boost::uuids::uuid tUuid = uuid_v4();   // 随机数生成
        std::string sUuid = boost::uuids::to_string(tUuid);
        std::string sResult;
        for (int i = 0; i < sUuid.size(); i++) {
            if (sUuid[i] != '-') {
                sResult.push_back(sUuid[i]);
            }
        }
        return sResult;
    }

    uint32_t GetCurrentTimestamp() {
        uint32_t uiTimeStamp;
        struct timeval tTime;
        ::gettimeofday(&tTime, NULL);
        uiTimeStamp = tTime.tv_sec * 1000 + tTime.tv_usec / 1000;
        return uiTimeStamp;
    }
};
